from pml.Parser.public import *

class Import(Node):
    def __init__(self, id=None, bp=None, ep=None, depth=0):
        super().__init__('import', bp, ep, depth)
        self.id = id
    def __repr__(self):
        return 'Import({})(\n{}id={}\n{})'.format(self.depth, '\t' * self.depth, self.id, '\t' * (self.depth - 1))

    def getObject(self):
        self.methods['__init__'] = self.tp_init

        return self

    @staticmethod
    def tp_init(frame, this, position):
        pass

class Include(Node):
    def __init__(self, id=None, bp=None, ep=None, depth=0):
        super().__init__('include', bp, ep, depth)
        self.id = id

    def __repr__(self):
        return 'Include({})(\n{}id={}\n{})'.format(self.depth, '\t' * self.depth, self.id, '\t' * (self.depth - 1))

    def getObject(self):
        self.methods['__init__'] = self.tp_init

        return self

    @staticmethod
    def tp_init(frame, this, position):
        pass

class ModuleBuilder(ASTBuilder):
    def __init__(self, tokens=None, depth=None):
        super().__init__('Module', tokens, depth)

    def getObject(self):
        self.methods['__init__'] = self.tp_init

        self.methods['buildModule'] = self.buildModule

        return self

    @staticmethod
    def buildModule(frame, this: "ModuleBuilder", position):
        bp = this.token.bp
        keyword = this.token.value
        this.getNextToken()
        nameBuilder = Parser.Expression.ExpressionBuilder(this.tokens, depth=this.depth + 1)
        name = nameBuilder.buildExpression(frame, nameBuilder, position)
        del nameBuilder
        this.getLastToken()
        ep = this.token.ep
        try:
            this.getNextToken()
        except StopIteration:
            pass
        return Objects.object.PMTypeObject((Import if keyword == TokenConstants.Keywords.IMPORT else Include)(name, bp, ep, depth=this.depth).getObject())

    @staticmethod
    def tp_init(frame, this, position):
        pass
